package com.cn.ryc.controller;


import com.cn.ryc.model.User;
import com.cn.ryc.service.AuthService;
import com.cn.ryc.util.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping("/api/auth")
@Controller
public class AuthController {

    @Autowired
    private AuthService authService;

    //登录
    @PostMapping("/login")
    public ResponseEntity<?> login(@RequestBody User user) {
        return authService.login(user);
    }
    //注册
    @PostMapping("/register")
    public ResponseEntity<?> register(@RequestBody User user) {
        return authService.register(user);
    }
    // 检查用户名是否存在
    @PostMapping("/check-username")

    public ResponseEntity<?> checkUsername(@RequestBody String username) {
        return authService.checkUsername(username);
    }

    // 获取所有用户
    @GetMapping("/userList")

    public ResponseEntity<ApiResponse<List<User>>> getAllUser() {
        return authService.getAllUser();
    }
    //更新用户信息
    @PutMapping("/updateUser")
    public ResponseEntity<ApiResponse<String>> updateUser(@RequestBody User user) {
        return authService.updateUser(user);
    }

    //修改密码
    @PutMapping("/updatePassword")
    public ResponseEntity<ApiResponse<String>> updatePassword(@RequestBody User user) {
        return authService.updatePassword(user);
    }

    //根据id获取用户
    @GetMapping("/getUserById/{id}")
    public ResponseEntity<ApiResponse<User>> getUserById(@PathVariable("id") Long id) {
        return authService.getUserById(id);
    }

    //重置用户密码
    @PutMapping("/resetPassword")
    public ResponseEntity<ApiResponse<String>> resetPassword(@RequestBody User user) {
        return authService.resetPassword(user);
    }


} 